import {
    sendMsgBestSize,
    sendMsgCapture,
    sendMsgCloseVideo,
    sendMsgGetMainCameraID,
    sendMsgRefreshDev,
    sendMsgRotateL,
    sendMsgRotateR,
    sendMsgSetCutType,
    sendMsgShotBase64,
    sendMsgStopVideo,
    sendMsgZoom,
    StartCam,
    WsInit
} from "@/api/baucheSDK/WsUtil";

const camera = {
    canvas: undefined,
    webSocket: undefined,
    socketIp: "0.0.0.0",
    socketPort: 9002,
    secondCamera: {
        enable: false,
        canvas: undefined,
    },
    create: function (canvas, socketIp) {
        if (!canvas) {
            throw "canvas is null";
        }

        this.canvas = canvas;
        this.socketIp = socketIp;
        return this;
    },
    connect: function () {
        WsInit(this.canvas.parentElement.offsetWidth, this.canvas.parentElement.offsetHeight, 0, 0, true, this.canvas)
    },
    setResolution(camId, width, height) {
        sendMsgCloseVideo();
        StartCam(camId, width, height);
    },
    startVideo(camId, width, height){
        StartCam(camId, width, height);
    },
    setCutType(type) {
        sendMsgSetCutType(type);
    },
    captureImage: function (type) {
        sendMsgCapture(type);
    },
    rotateR() {
        sendMsgRotateR();
    },
    rotateL() {
        sendMsgRotateL();
    },
    zoomIn() {
        sendMsgZoom(1);
    },
    zoomOut() {
        sendMsgZoom(0);
    },
    getMainDev() {
        sendMsgGetMainCameraID()
    },
    bestSize() {
        sendMsgBestSize();
    },
    onlyBase64() {
        sendMsgShotBase64(1);
    },
    refresh() {
        sendMsgRefreshDev()
    },
    close() {
        sendMsgCloseVideo();
        sendMsgStopVideo();
        this.webSocket.close()
    }

}

export default camera;